//
//  CustomPickView.m
//  HappiGO
//
//  Created by Zhuo LaiQiang on 11-9-22.
//  Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
//

#import "CustomPickView.h"

@implementation CustomPickView

@synthesize delegate      =       _delegate;
@synthesize pick          =       _pick;
@synthesize pickSourceArray = _pickSourceArray;

#pragma mark - class method
+ (CustomPickView *)viewFromNibWithDelegate:(id<CustomPickViewDelegate>)delegate_  
                            pickSourceArray:(NSArray *)pickSourceArray_
{
    NSArray *viewArray = [[NSBundle mainBundle] loadNibNamed: @"CustomPickView" owner: nil options: nil];
    CustomPickView *customPickView = [viewArray objectAtIndex: 0];
    
    customPickView.pickSourceArray = pickSourceArray_;
    customPickView.delegate = delegate_;
    
    return customPickView;
}

- (NSString *)getPickValue
{
    NSString *pickSelectStr = [_pickSourceArray objectAtIndex: [_pick selectedRowInComponent: 0]];
    
    return pickSelectStr;
}

#pragma mark - @“确定”按钮响应方法
- (IBAction)fixedButtonIsPressed:(id)sender 
{
    if (_delegate && [_delegate respondsToSelector: @selector(fixedButtonIsPressed:)])
    {
        [_delegate fixedButtonIsPressed: self];
    }
}

#pragma mark - @“取消”按钮响应方法
- (IBAction)cancelButtonIsPressed:(id)sender 
{
    if (_delegate && [_delegate respondsToSelector: @selector(cancelButtonIsPressed:)])
    {
        [_delegate cancelButtonIsPressed: self];
    }
}

#pragma mark - UIPickDelegate
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return [_pickSourceArray count];
}


- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return [_pickSourceArray objectAtIndex: row];
}

- (void)dealloc 
{
    [_pickSourceArray release];
    
    
    [super dealloc];
}
@end
